//
//  XLSearchViewView.swift
//  XLWeiBo
//
//  Created by 李晓龙 on 16/9/20.
//  Copyright © 2016年 lixiaolong. All rights reserved.
//

import UIKit

class XLSearchView: UIView {

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var seatchButton: UIButton!
    @IBOutlet weak var searchTextFieldRightConstraint: NSLayoutConstraint!
    
    @IBAction func editBegainAction(_ sender: AnyObject) {
        
        searchTextFieldRightConstraint.constant = seatchButton.width
        
        UIView.animate(withDuration: 0.3) {
        
            self.layoutIfNeeded()
    }
        
    }
    @IBAction func searchButton(_ sender: AnyObject) {
        
        //失去第一响应者
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstraint.constant = 0
        
        UIView.animate(withDuration: 0.3) {
            
            self.layoutIfNeeded()
        }
        
  
    }
    
    //类方法创建xib
    class func searchView() -> XLSearchView {
        return UINib(nibName: "XLSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! XLSearchView
    }
    
        override func awakeFromNib() {
            searchTextField.layer.borderColor = UIColor.magenta.cgColor
            searchTextField.layer.borderWidth = 2
            searchTextField.layer.cornerRadius = 5
            searchTextField.layer.masksToBounds = true
        }
    
}











